/**
 *                            License
 * THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS  
 * CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). 
 * THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW.  
 * ANY USE OF THE WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR  
 * COPYRIGHT LAW IS PROHIBITED.
 * 
 * BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND  
 * AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE  
 * MAY BE CONSIDERED TO BE A CONTRACT,
 * THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED 
 * HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS.
 * 
 */
package com.lineage.server.model;

import java.util.HashMap;
import java.util.logging.Logger;

import com.lineage.server.model.Instance.L1HardinQuestInstance;
import com.lineage.server.model.map.L1VirtualMap;

/**
 * Class <code>L1HardinQuest</code> 哈丁副本任务.
 * 
 * @author jrwz
 * @version 2012-7-13下午04:59:58
 * @see com.lineage.server.model
 * @since JDK1.7
 */
public final class L1HardinQuest {
    /** 提示信息. */
    @SuppressWarnings("unused")
    private static final Logger LOG = Logger.getLogger(L1HardinQuest.class
            .getName());
    /** 集合. */
    private static HashMap<Integer, L1HardinQuestInstance> activeMaps;
    /** 实例. */
    private static L1HardinQuest instance;

    /**
     * 当第一次实例为空时才新建一个.
     * 
     * @return 实例
     */
    public static L1HardinQuest getInstance() {
        if (instance == null) {
            instance = new L1HardinQuest();
        }
        return instance;
    }

    /** 哈丁副本任务. */
    L1HardinQuest() {
        activeMaps = new HashMap<Integer, L1HardinQuestInstance>();
    }

    /**
     * 从集合中取得指定的元素.
     * 
     * @param mapId
     *            - 地图编号
     * @return 存储的实例
     */
    public L1HardinQuestInstance getActiveMaps(final int mapId) {
        if (!activeMaps.containsKey(mapId)) {
            return null;
        }
        return activeMaps.get(mapId);
    }

    /**
     * 取得正在进行中的数量.
     * 
     * @return 总数
     */
    public int getNumOfActiveMaps() {
        return activeMaps.size();
    }

    /**
     * 删除打开的新地图.
     * 
     * @param mapId
     *            - 地图编号
     */
    public void resetActiveMaps(final int mapId) {
        if (!activeMaps.containsKey(mapId)) {
            return;
        }
        activeMaps.remove(mapId);
        L1VirtualMap.getInstance().removeVirtualMap(mapId);
    }

    /**
     * 创建虚拟地图、HashMap生成.
     * 
     * @param mapId
     *            - 要拷贝的原始地图编号
     * @return 地图编号
     */
    public short setActiveMaps(final int mapId) {
        final int instanceMapId = L1VirtualMap.getInstance().addVirtualMap(
                mapId);
        final L1HardinQuestInstance obj = new L1HardinQuestInstance(
                (short) instanceMapId);
        activeMaps.put(instanceMapId, obj);
        return obj.getMapId();
    }
}
